package cn.com.code.design.web;

import cn.com.code.design.annotation.DoDoor;
import cn.com.code.design.rpc.config.UserInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhengpei
 * @date 2021/9/29
 */
@RestController
public class HelloWorldController {

  @Value("${server.port}")
  private int port;

  @RequestMapping(path = "/api/queryUserInfo", method = RequestMethod.GET)
  public UserInfo queryUserInfo(@RequestParam String userId) {
    // 白名单拦截
    List<String> userList = new ArrayList<>();
    userList.add("1001");
    userList.add("aaaa");
    userList.add("ccc");
    if (!userList.contains(userId)) {
      return new UserInfo("111","非白名单可访问用户拦截");
    }

    return new UserInfo("虫虫:" + userId, 19, "天津市南开区旮旯胡同100号");
  }

  @DoDoor(key = "userId", returnJson = "{\"code\":\"1111\",\"info\":\"非白名单可访问用户拦截！\"}")
  @RequestMapping(path = "/api/queryUserInfo/aop", method = RequestMethod.GET)
  public UserInfo queryUserInfoByAop(@RequestParam String userId) {
    // 白名单拦截
    return new UserInfo("虫虫:" + userId, 19, "天津市南开区旮旯胡同100号");
  }

}
